//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tencent.bugly;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.tencent.bugly.proguard.n;
import com.tencent.bugly.proguard.o;
import com.tencent.bugly.proguard.p;
import com.tencent.bugly.proguard.u;
import com.tencent.bugly.proguard.x;
import com.tencent.bugly.proguard.y;
import com.tencent.bugly.proguard.z;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public final class b {
    public static boolean a = true;
    public static List<a> b = new ArrayList();
    public static boolean c;
    private static p d;
    private static boolean e;

    private static boolean a(com.tencent.bugly.crashreport.common.info.a var0) {
        List var1 = var0.p;
        var0.getClass();
        String var10000;
        if (true) {
            var10000 = "bugly";
        } else {
            var0.getClass();
            var10000 = "";
        }

        String var2 = var10000;
        return var1 != null && var1.contains(var2);
    }

    public static synchronized void a(Context var0) {
        a(var0, (BuglyStrategy)null);
    }

    public static synchronized void a(Context var0, BuglyStrategy var1) {
        if (e) {
            x.d("[init] initial Multi-times, ignore this.", new Object[0]);
        } else if (var0 == null) {
            Log.w(x.a, "[init] context of init() is null, check it.");
        } else {
            com.tencent.bugly.crashreport.common.info.a var2;
            if (a(var2 = com.tencent.bugly.crashreport.common.info.a.a(var0))) {
                a = false;
            } else {
                String var3;
                if ((var3 = var2.f()) == null) {
                    Log.e(x.a, "[init] meta data of BUGLY_APPID in AndroidManifest.xml should be set.");
                } else {
                    a(var0, var3, var2.v, var1);
                }
            }
        }
    }

    public static synchronized void a(Context var0, String var1, boolean var2, BuglyStrategy var3) {
        if (e) {
            x.d("[init] initial Multi-times, ignore this.", new Object[0]);
        } else if (var0 == null) {
            Log.w(x.a, "[init] context is null, check it.");
        } else if (var1 == null) {
            Log.e(x.a, "init arg 'crashReportAppID' should not be null!");
        } else {
            e = true;
            if (var2) {
                c = true;
                x.b = true;
                x.d("Bugly debug模式开启，请在发布时把isDebug关闭。 -- Running in debug model for 'isDebug' is enabled. Please disable it when you release.", new Object[0]);
                x.e("--------------------------------------------------------------------------------------------", new Object[0]);
                x.d("Bugly debug模式将有以下行为特性 -- The following list shows the behaviour of debug model: ", new Object[0]);
                x.d("[1] 输出详细的Bugly SDK的Log -- More detailed log of Bugly SDK will be output to logcat;", new Object[0]);
                x.d("[2] 每一条Crash都会被立即上报 -- Every crash caught by Bugly will be uploaded immediately.", new Object[0]);
                x.d("[3] 自定义日志将会在Logcat中输出 -- Custom log will be output to logcat.", new Object[0]);
                x.e("--------------------------------------------------------------------------------------------", new Object[0]);
                x.b("[init] Open debug mode of Bugly.", new Object[0]);
            }

            x.a(" crash report start initializing...", new Object[0]);
            x.b("[init] Bugly start initializing...", new Object[0]);
            x.a("[init] Bugly complete version: v%s", new Object[]{"3.1.8"});
            com.tencent.bugly.crashreport.common.info.a var4;
            (var4 = com.tencent.bugly.crashreport.common.info.a.a(var0 = z.a(var0))).t();
            y.a(var0);
            d = p.a(var0, b);
            u.a(var0);
            com.tencent.bugly.crashreport.common.strategy.a var5 = com.tencent.bugly.crashreport.common.strategy.a.a(var0, b);
            n var6 = n.a(var0);
            if (a(var4)) {
                a = false;
            } else {
                var4.a(var1);
                x.a("[param] Set APP ID:%s", new Object[]{var1});
                var4 = var4;
                BuglyStrategy var11 = var3;
                if (var3 != null) {
                    String var7;
                    String var8;
                    if (!TextUtils.isEmpty(var7 = var3.getAppVersion())) {
                        if (var7.length() > 100) {
                            var8 = var7.substring(0, 100);
                            x.d("appVersion %s length is over limit %d substring to %s", new Object[]{var7, 100, var8});
                            var7 = var8;
                        }

                        var4.k = var7;
                        x.a("[param] Set App version: %s", new Object[]{var3.getAppVersion()});
                    }

                    try {
                        if (var11.isReplaceOldChannel()) {
                            if (!TextUtils.isEmpty(var8 = var11.getAppChannel())) {
                                if (var8.length() > 100) {
                                    var7 = var8.substring(0, 100);
                                    x.d("appChannel %s length is over limit %d substring to %s", new Object[]{var8, 100, var7});
                                    var8 = var7;
                                }

                                d.a(556, "app_channel", var8.getBytes(), (o)null, false);
                                var4.m = var8;
                            }
                        } else {
                            byte[] var12;
                            Map var13;
                            if ((var13 = d.a(556, (o)null, true)) != null && (var12 = (byte[])var13.get("app_channel")) != null) {
                                var4.m = new String(var12);
                            }
                        }

                        x.a("[param] Set App channel: %s", new Object[]{var4.m});
                    } catch (Exception var10) {
                        if (c) {
                            var10.printStackTrace();
                        }
                    }

                    if (!TextUtils.isEmpty(var8 = var3.getAppPackageName())) {
                        if (var8.length() > 100) {
                            var7 = var8.substring(0, 100);
                            x.d("appPackageName %s length is over limit %d substring to %s", new Object[]{var8, 100, var7});
                            var8 = var7;
                        }

                        var4.c = var8;
                        x.a("[param] Set App package: %s", new Object[]{var3.getAppPackageName()});
                    }

                    if ((var7 = var3.getDeviceID()) != null) {
                        if (var7.length() > 100) {
                            var8 = var7.substring(0, 100);
                            x.d("deviceId %s length is over limit %d substring to %s", new Object[]{var7, 100, var8});
                            var7 = var8;
                        }

                        var4.c(var7);
                        x.a("[param] Set device ID: %s", new Object[]{var7});
                    }

                    var4.e = var3.isUploadProcess();
                    y.a = var3.isBuglyLogUpload();
                }

                for(int var14 = 0; var14 < b.size(); ++var14) {
                    try {
                        if (var6.a(((a)b.get(var14)).id)) {
                            ((a)b.get(var14)).init(var0, var2, var3);
                        }
                    } catch (Throwable var9) {
                        if (!x.a(var9)) {
                            var9.printStackTrace();
                        }
                    }
                }

                com.tencent.bugly.crashreport.biz.b.a(var0, var3);
                long var15 = var3 != null ? var3.getAppReportDelay() : 0L;
                var5.a(var15);
                x.b("[init] Bugly initialization finished.", new Object[0]);
            }
        }
    }

    public static synchronized void a(a var0) {
        if (!b.contains(var0)) {
            b.add(var0);
        }

    }
}
